package zhtt;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import zhtt.demo01.Blog;
import zhtt.demo01.Dept;
import zhtt.demo01.User;

import java.util.List;

/**
 * Created by zhtt on 2017/4/29.
 */
public class DeptTest {

    @Test
    public void insertDept(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            Dept dept=new Dept("boy");
            int r=sqlSession.insert("zhtt.demo01.Dept.insertDept",dept);
            System.out.println(dept);
            System.out.println(r);
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void get(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=sqlSession.selectOne("zhtt.demo01.Dept.getDept",1);
            System.out.println(dept);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void getDept2(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=sqlSession.selectOne("zhtt.demo01.Dept.getDept2",1);
            System.out.println(dept);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void getDept3(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=sqlSession.selectOne("zhtt.demo01.Dept.getDept3",1);
            System.out.println(dept);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void like1(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=new Dept("b");
            List<Dept> deptList=sqlSession.selectList("zhtt.demo01.Dept.like1",dept);
            System.out.println(deptList);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void like3(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=new Dept("b");
            List<Dept> deptList=sqlSession.selectList("zhtt.demo01.Dept.like3",dept);
            System.out.println(deptList);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void like4(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=new Dept("b");
            List<Dept> deptList=sqlSession.selectList("zhtt.demo01.Dept.like4",dept);
            System.out.println(deptList);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void like5(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=new Dept("b");
            List<Dept> deptList=sqlSession.selectList("zhtt.demo01.Dept.like5",dept);
            System.out.println(deptList);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void like(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            System.out.println(sqlSession);
            Dept dept=new Dept("b");
            List<Dept> deptList=sqlSession.selectList("zhtt.demo01.Dept.like",dept);
            System.out.println(deptList);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }
}
